<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2022/6/13
 * Time: 9:39
 */

include_once ('conn.php');

if($_FILES['tp']['error'] ==0){

    $size = 1024*1024;
    if($_FILES['tp']['size'] < $size ){
//        echo "大小和诗";

        $arr = array('jpg','jpg','gif','png','jpeg');
        $name = explode('.',$_FILES['tp']['name']);

        $tm_name = end($name);
        $tpname = in_array($tm_name,$arr);


        if ($tpname === true){
            $tp_tmp = $_FILES['tp']['tmp_name'];

            if(!is_dir('./img')){
                mkdir('./img');
            }

            $d = './img/';
            $pd = move_uploaded_file($tp_tmp,$d.$_FILES['tp']['name']);

            $tpm = $d.$_FILES['tp']['name'];
        }

            $sql= "insert into `picture` value (null,'$tpm')";

            $pdsql = mysqli_query($conn,$sql);
            if($pd && $pdsql){
                echo "成功"."<a href='xianshi.php'>去看看</a>";
            }else{
                echo "失败";
            }





    }
}



